package com.ejuornal.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ejuornal.bean.SystemInfo;
import com.ejuornal.service.SystemInfoService;
import com.ejuornal.util.StrToIntArray;

@Component("sysInfoAction")
public class SysInfoAction extends BaseAction<SystemInfo> {
	private static final long serialVersionUID = 1L;
	private SystemInfo systemInfo;
	private String systemInfoId;
	private String itemName;
	private SystemInfoService systemInfoService;
	
	/**
	 * 添加系统信息
	 * @return
	 */
	public String addSysInfo(){
		systemInfoService.add(systemInfo);
		listSysInfo();
		return SUCCESS;
	}
	
	/**
	 * 删除系统信息
	 * @return
	 */
	public String delSysInfo(){
		systemInfoService.delete(StrToIntArray.ChangeStrToIntArray(systemInfoId));
		listSysInfo(); 
		return 	SUCCESS;
	}
	
	/**
	 * 根据SystemInfoId查找
	 * @return
	 * @throws Exception
	 */
	public String findById(){
		systemInfo = systemInfoService.findById(Integer.parseInt(systemInfoId));
		super.setRequestAttribute("systemInfo", systemInfo);
		return SUCCESS;
	}
	
	/**
	 * 前台实现各模块跳转
	 */
	public String goDiffer() {
		int itemNameNo = Integer.parseInt(itemName);
		//关于我们
		if (itemNameNo==1) {
			systemInfo = systemInfoService.findByName("关于我们");
			super.setRequestAttribute("systemInfo", systemInfo);
			return "aboutUs";
		}
		//广告服务
		else if (itemNameNo==2) {
			systemInfo = systemInfoService.findByName("广告服务");
			super.setRequestAttribute("systemInfo", systemInfo);
			return "adsService";
		}
		//联系我们
		else if (itemNameNo==3) {
			systemInfo = systemInfoService.findByName("联系方式");
			super.setRequestAttribute("systemInfo", systemInfo);
			return "contactUs";
		}
		//在线帮助
		else if (itemNameNo==4) {
			systemInfo = systemInfoService.findByName("在线帮助");
			super.setRequestAttribute("systemInfo", systemInfo);
			return "onlineHelp";
		}
		//版权声明
		else if (itemNameNo==5) {
			systemInfo = systemInfoService.findByName("版权声明");
			super.setRequestAttribute("systemInfo", systemInfo);
			return "copyright";
		}
		//服务条款
		else if(itemNameNo==6){
			systemInfo = systemInfoService.findByName("服务条款");
			super.setRequestAttribute("systemInfo", systemInfo);
			return "serviceClause";
		} else if(itemNameNo==7) {
		    systemInfo = systemInfoService.findByName("团队介绍");
		    super.setRequestAttribute("systemInfo", systemInfo);
            return "groupIntroduce";
		}
		else {
			return "error";
		}
	}
	
	/**
	 * 根据SystemInfoId查找
	 * @return
	 * @throws Exception
	 */
	public String lookById(){
		systemInfo = systemInfoService.findById(Integer.parseInt(systemInfoId));
		return SUCCESS;
	}
	
	/**
	 * 更新系统信息
	 * @return
	 */
	public String updateSysInfo(){
		systemInfoService.update(systemInfo);
		listSysInfo();
		return SUCCESS;
	}
	
	/**
	 * 系统信息列表
	 * @return
	 */
	public String listSysInfo(){
		List<SystemInfo> systemInfoList = systemInfoService.findAll();
		super.setRequestAttribute("systemInfo", systemInfoList);
		return SUCCESS;
	}
	public SystemInfo getSystemInfo() {
		return systemInfo;
	}
	public void setSystemInfo(SystemInfo systemInfo) {
		this.systemInfo = systemInfo;
	}
	public SystemInfoService getsysInfoService() {
		return systemInfoService;
	}
	@Resource(name="systemInfoService")
	public void setsysInfoService(SystemInfoService systemInfoService) {
		this.systemInfoService = systemInfoService;
	}

	public String getItemName() {
		return itemName;
	}

	public void setItemName(String itemName) {
		this.itemName = itemName;
	}

	public String getSystemInfoId() {
		return systemInfoId;
	}

	public void setSystemInfoId(String systemInfoId) {
		this.systemInfoId = systemInfoId;
	}
}
